﻿using System;

namespace SilenthinkContract.Domain
{
    public class AuctionOrder : BaseEntity<string>
    {
        //public Action<AuctionOrder> CompleteHandler { get; set; } 
        #region Properties
        /// <summary>
        /// 用户Id
        /// </summary>
        public int UserId { get; set; }
        /// <summary>
        /// 是否为虚拟物品
        /// </summary>
        public bool IsVirtual { get; set; }
        /// <summary>
        /// 竞购获得为0 补差为1
        /// </summary>
        public byte Category { get; set; }
        /// <summary>
        /// 拍品Id
        /// </summary>
        public int AuctionId { get; set; }
        /// <summary>
        /// 产品Id
        /// </summary>
        public int ProductId { get; set; }
        /// <summary>
        /// 变体Id
        /// </summary>
        public string ProductVariantId { get; set; }
        /// <summary>
        /// 拍品等级
        /// </summary>
        public AuctionGrade Grade { get; set; }
        /// <summary>
        /// 拍品名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }
        /// <summary>
        /// 竞购价格
        /// </summary>
        public decimal BidPrice { get; set; }
        /// <summary>
        /// 购买单价
        /// </summary>
        public decimal BuyPrice { get; set; }
        /// <summary>
        /// 参考价格
        /// </summary>
        public decimal MarketPrice { get; set; }
        /// <summary>
        /// 拍品图片
        /// </summary>
        public string PictureSrc { get; set; }
        /// <summary>
        /// 拍品数量
        /// </summary>
        public int Quantity { get; set; }
        /// <summary>
        /// 补差扣除额
        /// </summary>
        public decimal Deduction { get; set; }
        /// <summary>
        /// 运费及手续费
        /// </summary>
        public decimal AdditionalCharge { get; set; }
        /// <summary>
        /// 需要支付总金额
        /// </summary>
        public decimal Total { get; set; }
        /// <summary>
        /// 是否兑换为积分
        /// </summary>
        public bool? IntegralExchange { get; set; }
        public byte ShippingMethod { get; set; }
        public byte PaymentMethod { get; set; }
        public DateTime? PaidDate { get; set; }
        public DateTime? ShippingDate { get; set; }
        public DateTime? DeliveryDate { get; set; }
        public OrderStatus OrderStatus { get; set; }
        public ShippingStatus ShippingStatus { get; set; }
        public PaymentStatus PaymentStatus { get; set; }
        public DateTime Expiration { get; set; }
        public string AreaCode { get; set; }
        public string Receiver { get; set; }
        public string Phone { get; set; }
        public string Mobile { get; set; }
        public string Province { get; set; }
        public string City { get; set; }
        public string Area { get; set; }
        public string Address { get; set; }
        public string PostalCode { get; set; }
        public string InvoiceCategory { get; set; }
        public string InvoiceTitle { get; set; }
        public string InvoiceContent { get; set; }
        public string IpAddress { get; set; }
        /// <summary>
        /// 留言
        /// </summary>
        public string Mesage { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string Extra { get; set; }
        #endregion

        public void SetAddressInvoice(UserAddress address, UserInvoice invoice)
        {
            AreaCode = address.AreaCode;
            Receiver = address.Receiver;
            Phone = address.Phone;
            Mobile = address.Mobile;
            //Province = address.Province;
            //City = address.City;
            //Area = address.Area;
            Address = address.AreaCode;
            PostalCode = address.AreaCode;
            InvoiceCategory = invoice.Category;
            InvoiceTitle = invoice.Title;
            InvoiceContent = invoice.Content;
        }

        public UserTrade ToTrade(string title = null, string extra = null)
        {
            var trade = new UserTrade();
            trade.Id = Id;
            trade.UserId = UserId;
            trade.Title = string.IsNullOrEmpty(title) ? Name : title;
            trade.Category = 1;/*交易类型 0为购物 1为竞购 2为代充 代付等*/
            trade.FundFlow = 0;/*资金流转 1为收入 0为支出*/
            trade.Amount = Total;/*交易金额*/
            trade.Paid = 0;/*已支付金额(一个订单可能分多次支付)*/
            trade.Refunded = 0;/*退款金额*/
            trade.ForUserId = 0;
            trade.ForUserName = string.Empty;
            trade.AssistNo = string.Empty;
            trade.Extra = extra;/*扩展信息*/
            trade.Status = UserTradeStatus.Pending;/*交易状态 0为成功 1为待支付 2为失败*/
            trade.CreatedBy = CreatedBy;
            trade.CreatedOn = DateTime.Now;
            return trade;
        }
    }
}